package com.zt.springcloud.service.Impl;

import cloud.zt.springboot.utils.StringUtils;
import com.zt.springcloud.entity.Address;
import com.zt.springcloud.entity.User;
import com.zt.springcloud.mapper.UserMapper;
import com.zt.springcloud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author RedReins
 * @version 1.0
 * @description: TODO
 * @date 2021/8/28 18:06
 */

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User selectUserByUserName(String username) {
        return userMapper.selectUserByUserName(username);
    }

    @Override
    public User selectUserById(Long id) {
        return userMapper.selectUserById(id);
    }

    @Override
    public Integer addUserAddress(Address address) {
        return userMapper.addUserAddress(address);
    }

    @Override
    public List<Address> getAddressInfo(Long userid) {
        List<Address> addressInfo = userMapper.getAddressInfo(userid);
        addressInfo.stream().forEach(address -> {
            if(!StringUtils.isNull(address.getPhone()))
            address.setPhone(StringUtils.encodePhoneNumber(address.getPhone().toString()));
        });
        return addressInfo;
    }

    @Override
    public Integer updateAddressInfo(Address address) {
        return userMapper.updateAddressInfo(address);
    }
}
